#ifndef TIMER2_H
#define TIMER2_H

#include "ext_interrupt.h"
#include "typedefs.h"
#include "pindef.h"
#include "led.h"

void Rtc_Comp_8ms_Enable( void );
void Rtc_Comp_1s_Enable(void);
void Rtc_Init( void );
void Real_Time_Clock(void);
void TC2_KBD_INT(uInt8 value);
void InitTimer(void);
void SetTimerFine(long i_delay);
long GetTimerFine(void);
void Wait_Millisecondes(long tmp);

void SetTimerMinute(uInt8 battery,int time_minute);
int GetTimerMinute(uInt8 battery);

void SetTimerEvent(int time_minute);
int GetTimerEvent(void);

struct clock_time{
  uInt8 second;                  //enter the current time, date, month, and year
  uInt8 minute;
  uInt8 hour;
} ;

struct timer_time{
 volatile int timer_500ms;
 volatile long timer_fine  ;
 int timer_minute[2];
 int event_timer;
};


#define TIMER_BATT_1          0
#define TIMER_BATT_2          1

#define cRTCscale               0x05;	       						
#define RTC_OVF_vect	TIMER2_OVF_vect
#define RTC_COMP_vect	TIMER2_COMP_vect

/*********************** TIMING MICROSECONDE**********************************/
#define _1_MICROSECONDE			8
#define _4_MICROSECONDE			32
#define _10_MICROSECONDE		80
#define _20_MICROSECONDE		160
#define _50_MICROSECONDE		400
#define _100_MICROSECONDE		800
/*********************** TIMING MILLISECONDE**********************************/
#define _1_MILLISECONDE         8000
#define _2_MILLISECONDE         16000
#define _10_MILLISECONDE        80000
#define _50_MILLISECONDE        400000
#define _100_MILLISECONDE       800000
#define _200_MILLISECONDE       2*800000
#define _300_MILLISECONDE       3*800000
#define _400_MILLISECONDE       4*800000
#define _500_MILLISECONDE       5*800000
#define _600_MILLISECONDE       6*800000
#define _700_MILLISECONDE       7*800000
#define _800_MILLISECONDE       8*800000
#define _900_MILLISECONDE       9*800000
#define _1000_MILLISECONDE      10*800000


#define TIMER_BLINK_ECRAN_INIT             128    // (128*7.8ms = 1s)
#define TIMER_BLINK_ECRAN_CHARGE           256    // 2s
#define TIMER_BLINK_ECRAN_CHARGE_TIMING    256    // 2s

#endif
